import Vue from "vue";
import VueRouter from "vue-router";
import login from "../views/login.vue";
import home from "../views/home.vue";
import welcome from "../components/welcome.vue";
import namesearch from "../components/namesearch.vue";
import tbsh from "../components/tbsh.vue";//提币审核
import cbjl from "../components/cbjl.vue";//充币记录
import tbjl from "../components/tbjl.vue";//提币记录
import ggfb from "../components/ggfb.vue";//公告发布
import jtbl from "../components/jtbl.vue";//静态变量
import userInfo from "../components/userInfo.vue";//用户信息
import teamInfo from "../components/teamInfo.vue";//团队详情
import gmjl from "../components/gmjl.vue";//购买记录
import syjl from "../components/syjl.vue";//收益记录
import yelr from "../components/yelr.vue";//余额录入
import smrz from "../components/smrz.vue";//实名认证 
import hyset from "../components/hyset.vue";//合约设置 
import qwsyjl from "../components/qwsyjl.vue";//全网收益记录
import guamjl from "../components/guamjl.vue";//购买记录
import coinadmin from "../components/coinadmin.vue";//币种管理
import fltz from "../components/fltz.vue";//复利投资
import fileManage from "../components/fileManage.vue";//文件管理
import yxCenterSq from "../components/yxCenterSq.vue";//运营中心申请
import yxSqJl from "../components/yxSqJl.vue";//运营申请记录
Vue.use(VueRouter);

const routes = [
  { path: "/", redirect: "/login" },
  { path: "/login", name: "login", component: login },
  {
    path: "/home",
    name: "home",
    component: home,
    redirect: "/welcome",
    children: [
      { path: "/welcome", component: welcome, name: "welcome" },
      { path: "/namesearch", component: namesearch, name: "namesearch" },
      { path: "/tbsh", component: tbsh, name: "tbsh" },
      { path: "/cbjl", component: cbjl, name: "cbjl" },
      { path: "/tbjl", component: tbjl, name: "tbjl" },
      { path: "/ggfb", component: ggfb, name: "ggfb" },
      { path: "/jtbl", component: jtbl, name: "jtbl" },
      { path: "/userInfo", component: userInfo, name: "userInfo" },
      { path: "/teamInfo", component: teamInfo, name: "teamInfo" },
      { path: "/gmjl", component: gmjl, name: "gmjl" },
      { path: "/syjl", component: syjl, name: "syjl" },
      { path: "/yelr", component: yelr, name: "yelr" },
      { path: "/smrz", component: smrz, name: "smrz" },
      { path: "/hyset", component: hyset, name: "hyset" },
      { path: "/qwsyjl", component: qwsyjl, name: "qwsyjl" },
      { path: "/guamjl", component: guamjl, name: "guamjl" },
      { path: "/coinadmin", component: coinadmin, name: "coinadmin" },
      { path: "/fltz", component: fltz, name: "fltz" },
      { path: "/fileManage", component: fileManage, name: "fileManage" },
      { path: "/yxCenterSq", component: yxCenterSq, name: "yxCenterSq" },
      { path: "/yxSqJl", component: yxSqJl, name: "yxSqJl" },
    ],
  },
];

const router = new VueRouter({
  routes,
});

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  //     next()  放行    next('/login')  强制跳转
  if (to.path === "/login") return next();
  // if (to.path !== '/login') return next("/login")
  // 获取token 并判断
  const tokenStr = window.sessionStorage.getItem("token");
  if (!tokenStr) return next("/login");
  next();
});

export default router;
